var express=require('express');
var session = require('express-session');
var router=require('./router/router');
var app=express();
var bodyParser = require('body-parser');
app.set('trust proxy', 1);
app.use(session({
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: true
}));
app.use(bodyParser.urlencoded({ extended: false }));// parse application/x-www-form-urlencoded
app.set('view engine','ejs');
app.use(bodyParser.json());// parse application/json
app.use(express.static('public'));
app.use(express.static('avatar'));


app.get('/',router.showIndex);//注意这里不用传参，因为是通过回调函数传递的
app.get('/register',router.showRegister);
app.post('/doRegister',router.doRegister);

app.get('/login',router.showLogin);
app.post('/doLogin',router.doLogin);
app.get('/goAvatar',router.goAvatar);
app.post('/setAvatar',router.setAvatar);

app.get('/cut',router.cut);
app.get('/docut',router.docut);



app.use(function (req,res) {
    res.render('404',{
        "name":req.session.name,
        "active":'404'
    })
});

app.listen(3001);

console.log('应用启动在3001端口');
